﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutoMapper;
using DevWeb.Biztalk.DeploymentSettings.Data.CodeFirst;
using DevWeb.Biztalk.DeploymentSettings.WebUI.Models;
using Microsoft.Practices.Unity;
using BreadCrumbHelper.Core.Attributes;

namespace DevWeb.Biztalk.DeploymentSettings.WebUI.Controllers
{

   

    public class DeploymentLogController : BaseController
    {
        //
        // GET: /DeploymentLog/

        


        public ActionResult Index(int? id)
        {
            IQueryable<DeploymentLog> deployments = Context.DeploymentLogs.Include("IntegrationVersion").Include("IntegrationVersion.Integration").Include("TargetEnvironment").AsQueryable();


            if (id.HasValue)
            {
                deployments = from c in deployments
                              where c.IntegrationVersionId == id
                              select c;
                
            }
           

            var items = deployments.ToList();
            var model = Mapper.Map<List<DeploymentLogViewModel>>(items.OrderByDescending(p=>p.CreateDateTime));
            return View(model);
        }
    }
}